﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// Condition: Write a program that compares two char arrays
//            lexicographically ( letter by letter ).


class Lexicographically
{
    static void Main()
    {
        // 1. initialize first array

        Console.Write("Enter number of element in first char array: ");
        int n1 = int.Parse(Console.ReadLine());
        char[] firstArray = new char[n1];
        Console.WriteLine("Enter elements of first array: ");
        for (int index = 0; index < n1; index++)
        {
            Console.Write("element[{0}]= ", index);
            firstArray[index] = char.Parse(Console.ReadLine());
        }
        Console.WriteLine();
        Console.WriteLine(new string('-', 20));
        Console.WriteLine();

        // 2. initialize second array

        Console.Write("Enter number of element in second char array: ");
        int n2 = int.Parse(Console.ReadLine());
        char[] secondArray = new char[n2];
        Console.WriteLine("Enter elements of second array: ");
        for (int index = 0; index < n2; index++)
        {
            Console.Write("element[{0}]= ", index);
            secondArray[index] = char.Parse(Console.ReadLine());
        }
        Console.WriteLine();
        Console.WriteLine(new string('-', 20));
        Console.WriteLine();

        // 3. First compare - equal arrays length

        

        if (n1 == n2)
        {
            bool check = true;
            for (int i = 0; i < n1; i++)
            {
                if (firstArray[i] == secondArray[i])
                {
                    continue;
                }
                else
                {
                    check = false;
                    if (firstArray[i] < secondArray[i])
                    {
                        Console.WriteLine("FirstArray is Lexicographically earlier than second one.");
                    }
                    else if (firstArray[i] > secondArray[i])
                    {
                        Console.WriteLine("SecondArray is Lexicographically earlier than first one.");
                    }
                    break;
                }
                
            }

            if (check == true)
            {
                Console.WriteLine("Two arrays are Lexicographically equal.");
            }
        }

        // 4. Second compare - different arrays length

        if (n1 != n2)
        {
            int minN;
            if (n1 < n2)
            {
                minN = n1;
            }
            else
            {
                minN = n2;
            }
                bool check = true;
                for (int i = 0; i < minN; i++)
                {
                    if (firstArray[i] == secondArray[i])
                    {
                        continue;
                    }
                    else
                    {
                        check = false;
                        if (firstArray[i] < secondArray[i])
                        {
                            Console.WriteLine("FirstArray is Lexicographically earlier than second one.");
                        }
                        else if (firstArray[i] > secondArray[i])
                        {
                            Console.WriteLine("SecondArray is Lexicographically earlier than first one.");
                        }
                        break;
                    }

                }

                if (check == true && n1 == minN)
                {
                    Console.WriteLine("FirstArray is Lexicographically earlier than second one.");
                }
                else if (check == true && n2 == minN)
                {
                    Console.WriteLine("SecondArray is Lexicographically earlier than first one.");
                }
        }
    }
}

